package dao;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class InviteDao {
	private Log log = LogFactory.getLog(InviteDao.class);
	
	public List findByHql(String hql) {
		log.debug("finding LoginUser instance by hql");
		//读取 Hibernate 配置文件 生成 SessionFactory，对Session进行管理
		SessionFactory sf= new Configuration().configure().buildSessionFactory();
		
		//打开一个session
		Session session=sf.openSession();
		try {
			String queryString = hql;
			Query queryObject = session.createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			
			log.error("find by hql failed", re);
			throw re;
		} finally{
			//对应打开 这里关闭
			session.close();
		}
	}
}
